package org.reenscape.remote;
import java.net.*;
import java.io.*;
import java.util.*;
/**
*@author Troy Osborne
*/
public class Communicator implements Runnable {

	private Socket socket;

	public Communicator(Socket skt) {
		socket = skt;
	}

	public void run() {
		try {
			while(true) {
				BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				PrintWriter out = new PrintWriter(socket.getOutputStream());
				out.println("ReenScape Telnet");
				out.println("Authorization: ");
				out.flush();
				boolean auth = false;
				do {
					do {
						out.println();
						out.print("Username: ");
						out.flush();
					} while(!in.readLine().equals("shift"));
					out.println();
					out.print("Password: ");
					out.flush();
					if(in.readLine().equals("101020")) {
						auth=true;
					}
				} while(auth == false);
				out.println();
				out.println("Authorization successful.");
				out.println("You are now connected.");
				out.println();
				out.flush();
				Console con = new Console(socket.getInputStream(), socket.getOutputStream());
				con.run();
				con.printHelp();
			}
		} catch (Exception e) {}
	}
}